package studentmanager;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;

import structure.Course;

public class GUICourseCell extends JPanel implements ListCellRenderer<Course>{

	private static final long serialVersionUID = 1L;
	private JLabel courseTittle;
	private JLabel dateandtime;
	private boolean isSelected;
	
	public GUICourseCell() {
		setLayout(new BorderLayout());
		setOpaque(false);
		setBorder(new EmptyBorder(2, 10, 0, 10));
		courseTittle = new JLabel();
		courseTittle.setFont(getFont().deriveFont(16f));
		courseTittle.setForeground(Color.DARK_GRAY);
		
		dateandtime = new JLabel();
		dateandtime.setFont(getFont().deriveFont(14f));
		dateandtime.setForeground(Color.gray);
		
		add(courseTittle, BorderLayout.NORTH);
		add(dateandtime,BorderLayout.CENTER);
		
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		g.setColor(new Color(255,255,255,0));
		if(isSelected){
			g.setColor(new Color(0, 0, 0,10));
		}
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(new Color(0, 0, 0,50));
		g.drawLine(0, this.getHeight()-1, this.getWidth()-1, this.getHeight()-1);
		super.paintComponent(g);
	}

	@Override
	public Component getListCellRendererComponent(JList<? extends Course> list,
			Course value, int index, boolean isSelected, boolean cellHasFocus) {
		this.courseTittle.setText(value.getCourseTitle());
		String temp = "Thời gian: " + value.getDateOfExam()  + " " + value.getTimeOfExam();
		this.dateandtime.setText(temp);
		if(isSelected){
			if(!this.isSelected){
				this.isSelected = isSelected;
			}
		}else{
			if(this.isSelected){
				this.isSelected = isSelected;
			}
		}
		return this;
	}
	
	

}
